﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _3D_Processor
{
    public partial class Add_Menually : Form
    {
        public Add_Menually()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Add left camera image
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.CheckFileExists = true;
            ofd.Filter = "Image files|*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tiff";
            ofd.Multiselect = false;

            System.Windows.Forms.DialogResult dr = ofd.ShowDialog();
            if (dr != System.Windows.Forms.DialogResult.OK) return;
            lImageLoc.Text = ofd.FileName;
            ofd.Dispose();
        }

        /// <summary>
        /// Add right camera image
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.CheckFileExists = true;
            ofd.Filter = "Image files|*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tiff";
            ofd.Multiselect = false;

            System.Windows.Forms.DialogResult dr = ofd.ShowDialog();
            if (dr != System.Windows.Forms.DialogResult.OK) return;
            rImageLoc.Text = ofd.FileName;
            ofd.Dispose();
        }

        /// <summary>
        /// close the dialogue box without adding images in que
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancleButton_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        /// <summary>
        /// Add Images in que
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddImage_Click(object sender, EventArgs e)
        {
            if(string.IsNullOrEmpty(lImageLoc.Text)||string.IsNullOrEmpty(rImageLoc.Text))
            {
                MessageBox.Show("You must select left and right image first", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Bitmap lbmp = (Bitmap)Bitmap.FromFile(lImageLoc.Text);
            Bitmap rbmp = (Bitmap)Bitmap.FromFile(rImageLoc.Text);
            if (lbmp.Height != rbmp.Height || lbmp.Width != rbmp.Width)
            {
                lbmp.Dispose();
                rbmp.Dispose();
                MessageBox.Show("Sorry the images you have selected have different resolution, so I am unable to process them", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            MainForm.RightImages.Add(rbmp);
            MainForm.LeftImages.Add(lbmp);
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }


    }
}
